home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / janusw.zip / JANUSWN.PAS < prev    next >
Pascal/Delphi Source File  |  1992-07-26  |  5KB  |  166 lines

  1. Unit JanusWn;
  2. { Unit:      JanusWn
  3.   Version:   1.00
  4.   Purpose:   tJanusDialogWindow is a descendant of tDialogWindow that
  5.              is able to create a (modeless) BorDlg from a standard resource
  6.              and vice versa.
  7.   Features:  - no wObjectB is needed
  8.              - let the user decide at runtime whether to use BorDlgs or
  9.                standard dialogs
  10.   Bonus:     national language support for BorButtons: if you intend to
  11.              have for example a german version of Borlands "&No" button
  12.              in your program, it's that simple: just put a "&Nein"
  13.              BorButton with id 7 in your resource and tJanusDialogWindow
  14.              automatically loads the bitmaps for you.
  15.   Date:      22.4.1992
  16.  
  17.   Developer: Peter Sawatzki (PS)
  18.              Buchenhof 3, D-5800 Hagen 1, Germany
  19.  CompuServe: 100031,3002
  20.        FIDO: 2:245/5800.17
  21.      BITNET: IN307@DHAFEU11
  22.  
  23.   Copyright (c) 1992 Peter Sawatzki. All Rights Reserved.
  24. }
  25. Interface
  26. Uses
  27.   WinTypes,
  28.   WObjects,
  29.   DialogWn;
  30. Type
  31.   pJanusDialogWindow = ^tJanusDialogWindow;
  32.   tJanusDialogWindow = Object(tDialogWindow)
  33.     useBWCC: Boolean;
  34.     Constructor Init (aParent: pWindowsObject; aName: pChar; BorStyle: Boolean);
  35.     Procedure SetClassName; Virtual;
  36.     Procedure GetChildClass (Var aChildClass: tChildClass); Virtual;
  37.     Function CreateDialogChild (Var aChildClass: tChildClass): hWnd; Virtual;
  38.   End;
  39.  
  40. Implementation
  41. Uses
  42.   WinProcs,
  43.   Strings;
  44.  
  45. Const
  46.   BorDialog = 'BorDlg';
  47.   BorButton = 'BorBtn';
  48.   BorRadio  = 'BorRadio';
  49.   BorStatic = 'BorStatic';
  50.   BorCheck  = 'BorCheck';
  51.   BorShade  = 'BorShade';
  52.  
  53.   bss_Group = 1; {group box}
  54.   bss_Hdip  = 2; {horizontal border}
  55.   bss_Vdip  = 3; {hertical border}
  56.   bss_Hbump = 4; {horizontal speed bump}
  57.   bss_Vbump = 5; {vertical speed bump}
  58.  
  59. Const
  60.   BWCCInst: tHandle = tHandle(0);
  61.  
  62. Function LoadBWCC: Boolean;
  63. Var
  64.   aWndClass: tWndClass;
  65. Begin
  66.   If BWCCInst=0 Then Begin
  67.     BWCCInst:= LoadLibrary('BWCC.DLL');
  68.     If BWCCInst<32 Then Begin
  69.       LoadBWCC:= False;
  70.       BWCCInst:= 0;
  71.       Exit
  72.     End
  73.   End;
  74.   LoadBWCC:= GetClassInfo(System.hInstance,BorStatic,aWndClass)
  75. End;
  76.  
  77. Constructor tJanusDialogWindow.Init (aParent: pWindowsObject; aName: pChar; BorStyle: Boolean);
  78. Begin
  79.   useBWCC:= BorStyle And LoadBWCC;
  80.   tDialogWindow.Init(aParent, aName);
  81.   If useBWCC Then
  82.     If IsFlagSet(wb_MDIChild) Then
  83.       DefaultProc:= GetProcAddress(BWCCInst,'BWCCDefMdiChildProc')
  84.     Else
  85.       DefaultProc:= GetProcAddress(BWCCInst,'BWCCDefWindowProc')
  86. End;
  87.  
  88. Procedure tJanusDialogWindow.SetClassName;
  89. Var
  90.   pureClassName,
  91.   tempClassName : Array[0..127] Of Char;
  92. Begin
  93.   tDialogWindow.SetClassName;
  94.   With DialogAttr Do Begin
  95.     If ClassName=Nil Then
  96.       pureClassName[0]:= #0
  97.     Else Begin
  98.       If StrLIComp(ClassName,BorDialog,Length(BorDialog))=0 Then
  99.         StrCopy(pureClassName,ClassName+Length(BorDialog)) {extract without 'BorDlg'}
  100.       Else
  101.         StrCopy(pureClassName,ClassName);
  102.       StrDispose(ClassName)
  103.     End;
  104.     If useBWCC Then
  105.       ClassName:= StrNew(StrCat(StrCopy(tempClassName,BorDialog),pureClassName))
  106.     Else
  107.       ClassName:= StrNew(pureClassName)
  108.   End
  109. End;
  110.  
  111. Procedure tJanusDialogWindow.GetChildClass (Var aChildClass: tChildClass);
  112. Begin With aChildClass Do
  113.   If useBWCC Then
  114.     Case szClass[0] Of
  115.       #$80: Case dwStyle And $F Of
  116.               bs_CheckBox,
  117.               bs_AutoCheckBox:        StrCopy(szClass,BorCheck);
  118.               bs_RadioButton..bs_Auto3State,
  119.               bs_AutoRadioButton:     StrCopy(szClass,BorRadio);
  120.               bs_GroupBox:            StrCopy(szClass,BorShade);
  121.             Else
  122.               StrCopy(szClass,BorButton)
  123.             End;
  124.       #$82: StrCopy(szClass,BorStatic);
  125.     Else
  126.       tDialogWindow.GetChildClass(aChildClass)
  127.     End
  128.   Else
  129.     If      (StrIComp(szClass,BorCheck)=0)
  130.     Or      (StrIComp(szClass,BorRadio)=0)
  131.     Or      (StrIComp(szClass,BorButton)=0) Then szClass[0]:= #$80
  132.     Else If (StrIComp(szClass,BorStatic)=0) Then szClass[0]:= #$82
  133.     Else If (StrIComp(szClass,BorShade)=0)  Then
  134.       Case dwStyle And $F Of
  135.         bss_Group: Begin szClass[0]:= #$80; dwStyle:= dwStyle And $FFFFFFF0 Or bs_GroupBox End;
  136.         bss_Hdip,
  137.         bss_Hbump,
  138.         bss_Vdip,
  139.         bss_Vbump: Begin szClass[0]:= #$82; dwStyle:= dwStyle And $FFFFFFF0 Or ss_BlackRect End;
  140.       End;
  141.     tDialogWindow.GetChildClass(aChildClass)
  142. End;
  143.  
  144. Function tJanusDialogWindow.CreateDialogChild (Var aChildClass: tChildClass): hWnd;
  145. Var
  146.   aCtl: hWnd;
  147.   BitHandle: array[0..2] of hBitmap;
  148. Const
  149.   bbm_SetBits = (BM_SETSTYLE+10);
  150. Begin
  151.   aCtl:= tDialogWindow.CreateDialogChild(aChildClass);
  152.   If (aCtl<>0) And useBWCC Then Begin
  153.     BitHandle[0] := LoadBitmap(hInstance,pChar(1000+aChildClass.wID)); { Normal }
  154.     If BitHandle[0]<>0 Then Begin
  155.       BitHandle[1] := LoadBitmap(hInstance,pChar(3000+aChildClass.wID)); { Pressed }
  156.       BitHandle[2] := LoadBitmap(hInstance,pChar(5000+aChildClass.wID)); { Selected }
  157.       If BitHandle[2]=0 Then BitHandle[2]:= BitHandle[0];
  158.       If BitHandle[1]=0 Then BitHandle[1]:= BitHandle[2];
  159.       SendMessage(aCtl,BBM_SETBITS,0,Longint(@BitHandle));
  160.       SetWindowText(aCtl,Nil)
  161.     End
  162.   End;
  163.   CreateDialogChild:= aCtl
  164. End;
  165. End.
  166.